package test1;

public class CalcBMI {
    private double height;
    private double weight;

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public void setParams(double height, double weight) {
        this.height = height;
        this.weight = weight;
    }


//    public CalcBMI(double height, double weight) {
//        this.height = height;
//        this.weight = weight;
//    }

    public CalcBMI() {
        // 需要重写无参构造方法，使用setParams设置变量值
    }

    /**
     * 计算 BMI 指数, BMI = 体重 / 身高 ^ 2
     * bmi = weight / height * height
     */
    public String getBMIType() {
        double bmi = 0.0;
        String result = "";

        if (weight > 0 && height > 0) {
            //1.计算bmi
            bmi = weight / (height * height);
            //2.根据bmi判断所属健康分类
            if (bmi < 18.5) {
                result = "偏瘦";
            } else if (bmi < 24) {
                result = "正常";
            } else if (bmi < 28) {
                result = "偏胖";
            } else {
                result = "肥胖";
            }
        } else {
            if (height == 0 || weight == 0) throw new RuntimeException("输入参数不能为0");
            return "输入错误";
        }
        return result;
    }
}
